<?php

namespace app\admin\model\node;

use think\Model;

class Nodeattr extends Model
{
    // 表名
    protected $name = 'node_attr';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    
    // 追加属性
    protected $append = [
        'ab_tongji_text',
        'area_text'
    ];
    
    protected static function init()
    {
        self::beforeUpdate(function ($row) {
            $row->time = date("Y-m-d H:i:s",time());
        });
    }
    
    public function getAbTongjiList()
    {
        return ['1' => __('Ab_tongji 1'),'2' => __('Ab_tongji 2')];
    }     

    public function getAreaList()
    {
        return ['1' => __('Area 1'),'2' => __('Area 2')];
    }     


    public function getAbTongjiTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['ab_tongji']) ? $data['ab_tongji'] : '');
        $list = $this->getAbTongjiList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getAreaTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['area']) ? $data['area'] : '');
        $list = $this->getAreaList();
        return isset($list[$value]) ? $list[$value] : '';
    }




}
